package com.example.demo.util;

import java.io.Serializable;
import java.util.Objects;

/**
 * 基本返回结果
 *
 * @author kecc
 * @date 2018/12/3
 */
public class BaseResult implements Serializable {

    private static final long serialVersionUID = 2641600677920985792L;

    /** 状态码 */
    private String code;

    /** 状态消息（可以为空）*/
    private String message;

    private Boolean success;

    public static class BaseResultBuilder {
        private String code    = "";
        private String message = "";

        public static BaseResultBuilder newBuilder() {
            return new BaseResultBuilder();
        }

        public BaseResultBuilder code(String code) {
            this.code = code;
            return this;
        }

        public BaseResultBuilder message(String message) {
            this.message = message;
            return this;
        }

        public BaseResult build() {
            return new BaseResult(this);
        }
    }

    public BaseResult() {
    }

    protected BaseResult(BaseResultBuilder builder) {
        this.code = builder.code;
        this.message = builder.message;
    }

    public boolean isSuccess() {
        return Objects.equals(code, ResultCode.SUCCESS);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    @Override
    public String toString() {
        return "BaseResult{" + "code=" + code + ", message='" + message + '\'' + '}';
    }

    public BaseResult(String code, String message, Boolean success) {
        super();
        this.code = code;
        this.message = message;
        this.success = success;
    }
}
